package com.example.tnot.Teacher.Homepart.InternalFragment.Ai;

import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class AIHomeFragment extends BaseBackFragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;
    View view;
    ImageView iv_back;
    TextView tv_ai_teaching,tv_ai_application,tv_ai_practice,tv_ai_analysis;
    LinearLayout ll_deep_thinking,ll_photo_qna,ll_books_resources,ll_writing,ll_other,ll_showBook,ll_question,ll_application;
    HorizontalScrollView hs_teach;
    ScrollView sc_analysis;
    EditText et_question,et_practiceQuestion;
    private List<TextView> typeList;

    public AIHomeFragment() {
    }

    public static AIHomeFragment newInstance(String param1, String param2) {
        AIHomeFragment fragment = new AIHomeFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.home_ai, container, false);
        InitData();
        InitView();
        serListener();
        return view;
    }

    private void InitData() {
        typeList = new ArrayList<>();
    }


    private void InitView() {
        iv_back = view.findViewById(R.id.iv_back);
        tv_ai_teaching = view.findViewById(R.id.tv_ai_teaching);
        tv_ai_application = view.findViewById(R.id.tv_ai_application);
        tv_ai_practice = view.findViewById(R.id.tv_ai_practice);
        tv_ai_analysis = view.findViewById(R.id.tv_ai_analysis);
        ll_deep_thinking = view.findViewById(R.id.ll_deep_thinking);
        ll_photo_qna = view.findViewById(R.id.ll_photo_qna);
        ll_books_resources = view.findViewById(R.id.ll_books_resources);
        ll_writing = view.findViewById(R.id.ll_writing);
        ll_other = view.findViewById(R.id.ll_other);
        ll_showBook = view.findViewById(R.id.ll_showBook);
        ll_question = view.findViewById(R.id.ll_question);
        hs_teach = view.findViewById(R.id.hs_teach);
        sc_analysis = view.findViewById(R.id.sc_analysis);
        et_question = view.findViewById(R.id.et_question);
        et_practiceQuestion = view.findViewById(R.id.et_practiceQuestion);
        ll_application = view.findViewById(R.id.ll_application);
    }

    private void serListener() {
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigateUp();
            }
        });
        SwitchMode();

        ll_deep_thinking.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        ll_photo_qna.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        ll_books_resources.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll_showBook.setVisibility(ViewGroup.VISIBLE);

            }
        });
        ll_writing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        ll_other.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });


    }

    private void SwitchMode() {
        tv_ai_teaching.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("UseCompatLoadingForDrawables")
            @Override
            public void onClick(View v) {
                if (!typeList.isEmpty()){
                    typeList.clear();
                }
                typeList= new ArrayList<>(Arrays.asList(tv_ai_practice,tv_ai_application,tv_ai_analysis));
                tv_ai_teaching.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
                tv_ai_teaching.setTextColor(getResources().getColor(R.color.white));
                for (TextView textView : typeList) {
                    textView.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
                    textView.setTextColor(0xFF666666);
                }
                //将输入框的上面的按钮更新
                ll_application.setVisibility(View.GONE);
                hs_teach.setVisibility(View.VISIBLE);

                //将学情分析页面的字隐藏
                sc_analysis.setVisibility(View.GONE);

//                tv_ai_teaching.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
//                tv_ai_teaching.setTextColor(getResources().getColor(R.color.white));
//                tv_ai_practice.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_application.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_analysis.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
            }
        });
        tv_ai_application.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("UseCompatLoadingForDrawables")
            @Override
            public void onClick(View v) {
                if (!typeList.isEmpty()){
                    typeList.clear();
                }
                typeList = new ArrayList<>(Arrays.asList(tv_ai_teaching,tv_ai_practice,tv_ai_analysis));
                tv_ai_application.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
                tv_ai_application.setTextColor(getResources().getColor(R.color.white));
                for (TextView textView : typeList){
                    textView.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
                    textView.setTextColor(0xFF666666);
                }
                //将点击的按钮隐藏
                ll_question.setVisibility(ViewGroup.VISIBLE);
                hs_teach.setVisibility(ViewGroup.GONE);
                //将分析页面的字隐藏
                sc_analysis.setVisibility(View.GONE);

                ll_application.setVisibility(View.VISIBLE);
                hs_teach.setVisibility(View.GONE);
//                tv_ai_application.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
//                tv_ai_teaching.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_practice.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_analysis.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
            }
        });
        tv_ai_practice.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("UseCompatLoadingForDrawables")
            @Override
            public void onClick(View v) {
                if (!typeList.isEmpty()){
                    typeList.clear();
                }
                typeList = new ArrayList<>(Arrays.asList(tv_ai_teaching,tv_ai_application,tv_ai_analysis));
                tv_ai_practice.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
                tv_ai_practice.setTextColor(getResources().getColor(R.color.white));
                for (TextView textView : typeList){
                    textView.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
                    textView.setTextColor(0xFF666666);
                }
                //将点击的按钮隐藏
                ll_application.setVisibility(ViewGroup.GONE);
                hs_teach.setVisibility(ViewGroup.GONE);
                //切换搜索条样式
                et_question.setVisibility(ViewGroup.GONE);
                et_practiceQuestion.setVisibility(ViewGroup.VISIBLE);
                //将学情分析的字隐藏
                sc_analysis.setVisibility(View.GONE);
//                tv_ai_practice.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
//                tv_ai_teaching.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_application.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_analysis.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));

            }
        });
        tv_ai_analysis.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("UseCompatLoadingForDrawables")
            @Override
            public void onClick(View v) {
                if (!typeList.isEmpty()){
                    typeList.clear();
                }
                typeList = new ArrayList<>(Arrays.asList(tv_ai_teaching,tv_ai_application,tv_ai_practice));
                tv_ai_analysis.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
                tv_ai_analysis.setTextColor(getResources().getColor(R.color.white));
                for (TextView textView : typeList){
                    textView.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
                    textView.setTextColor(0xFF666666);
                }
                ll_question.setVisibility(ViewGroup.GONE);
                hs_teach.setVisibility(ViewGroup.GONE);
                sc_analysis.setVisibility(ViewGroup.VISIBLE);
                et_question.setVisibility(ViewGroup.VISIBLE);
                et_practiceQuestion.setVisibility(ViewGroup.GONE);
//                tv_ai_analysis.setBackground(getResources().getDrawable(R.drawable.selected_tab_background));
//                tv_ai_teaching.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_application.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));
//                tv_ai_practice.setBackground(getResources().getDrawable(R.drawable.unselected_tab_background));

            }
        });
    }

}